<?php
namespace app\home\controller;
use think\Db;
class Article extends Base
{

    //文章详情页
    function detail()
    {
        $id = input('id');
        Db::name('article')->where('article_id',$id)->setInc('read_count');
        $article = Db::name('article')->alias('a')->join('user u','a.uid = u.uid')->join('category c','a.category_id = c.id')->where("article_id",$id)->find();
        if(!$article){
            $this->error("噢，只是一片空虚寂寞喔","/");
        }
     

        return view("/article-detail",[
            "article" => $article,
        ]);

    }

    public function category()
    {
        $categoryId = input("id");
        $pageNumber = input("pageNumber");
        if (empty($pageNumber)){
            $pageNumber = 10;
        }
        $articleList = Db::name('article')
            ->alias('a')
            ->join('user u','a.uid = u.uid')
            ->join('category c','a.category_id = c.id')
            ->order("article_id desc")
            ->where("category_id", $categoryId)
            ->paginate($pageNumber);
        $categoryName = Db::name("category")->where("id", $categoryId)->value("category_name");
        return view("/category-article",["articleList" => $articleList,"tagName" => $categoryName]);
    }
}